package com.example.bill.service;

import com.example.bill.dao.BillMapper;
import com.example.bill.vo.BillVo;
import com.example.result.CommonResult;
import com.example.utils.MyPageHelper;
import com.example.utils.NumUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class BillServiceImpl implements BillService{
    @Autowired
    BillMapper billMapper;
    /**
     * 收费管理-账单全查
     * @param billState
     * @return
     */
    @Override
    public CommonResult getBill(String billState) {
        return CommonResult.ok(MyPageHelper.getPageResult(billMapper.getBill(billState)));
    }

    /**
     * 收费管理-账单删除
     * @param id
     * @return
     */
    @Override
    public int delBill(Integer id) {
        int i = billMapper.delBill(id);
        return i;
    }

    /**
     * 收费管理-账单增改
     * @param billVo
     * @return
     */
    @Override
    public int saveOrUpdateBill(BillVo billVo) {
        int i = 0;
        if(billVo.getId() == 0){
            int num = NumUtil.Num();
            billVo.setBillOrderNumber(num);
            billVo.setCreateTime(new Date());
            billVo.setUpdateTime(new Date());
            billVo.setBillDelFlag(0);
            i = billMapper.addBill(billVo);
        }else {
            billVo.setUpdateTime(new Date());
            i = billMapper.updateBill(billVo);
        }
        return i;
    }
}
